﻿<Controls:CustomWindow Style="{StaticResource {x:Type Controls:CustomWindow}}"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:helper="clr-namespace:Starehe;assembly=Helper"
        xmlns:converters="clr-namespace:Helper.Converters;assembly=Helper"
        xmlns:Controls="clr-namespace:Helper.Controls;assembly=Helper" x:Class="Starehe.Views.StartupRepair"
        Title="Startup Repair" Height="560" Width="800" ResizeMode="NoResize" WindowStartupLocation="CenterScreen"
                       >
    <Window.Resources>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <converters:InverseVisibilityConverter x:Key="InverseVisibilityConverter"/>
    </Window.Resources>
    <Grid>
        <TextBlock HorizontalAlignment="Left" Margin="20,20,0,0" Style="{DynamicResource TitleXL}"  Text="Startup" VerticalAlignment="Top"/>
        <TextBlock Margin="30,90,103,0" Style="{DynamicResource Title0}" 
                   TextWrapping="WrapWithOverflow" Text="{Binding Message}" 
			VerticalAlignment="Top"/>
        <Grid Name="repairingGrid" Visibility="{Binding RepairInProgress, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">
            <TextBlock HorizontalAlignment="Left" Margin="30,164,0,0" VerticalAlignment="Top">
                   
            <Hyperlink Command="{Binding ShowDetailsCommand}"><Run Text="Details"/></Hyperlink>
            </TextBlock>
            <Grid Margin="77,200,0,0" HorizontalAlignment="Left" Width="193" Height="170" VerticalAlignment="Top"
              Visibility="{Binding ShowDetails, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">

                <Controls:ProgressText TaskState="{Binding CreatingBackup, Mode=OneWay}"                           
        		HorizontalAlignment="Left" Description="Create Backup" VerticalAlignment="Top" Width="152"/>

                <Controls:ProgressText TaskState="{Binding RepairingInstallation, Mode=OneWay}"    
        		HorizontalAlignment="Left" Margin="0,30,0,0" Description="Microsoft SQL Server Installation" VerticalAlignment="Top"/>

                <Controls:ProgressText TaskState="{Binding RepairingInstance, Mode=OneWay}" 
        		HorizontalAlignment="Left" Margin="0,60,0,0" Description="Server Instance" VerticalAlignment="Top"/>

                <Controls:ProgressText TaskState="{Binding RepairingDefaultLogin, Mode=OneWay}"    
        		HorizontalAlignment="Left" Margin="0,90,0,0" Description="Server Login" VerticalAlignment="Top"/>

                <Controls:ProgressText TaskState="{Binding RepairingDb, Mode=OneWay}"   
        		HorizontalAlignment="Left" Margin="0,120,0,0" Description="Database" VerticalAlignment="Top"/>

                <Controls:ProgressText TaskState="{Binding RepairingDbObjects, Mode=OneWay}"   
        		HorizontalAlignment="Left" Margin="0,150,0,0" Description="Database Objects" VerticalAlignment="Top"/>

            </Grid>

            <ProgressBar Height="10" Margin="0,0,0,50" VerticalAlignment="Bottom" IsIndeterminate="True" 
                    />

        </Grid>

        <Grid Visibility="{Binding ShowErrors, Converter={StaticResource BooleanToVisibilityConverter}}">
            <TextBlock Style="{DynamicResource Title1}" HorizontalAlignment="Left" Margin="30,164,0,0" Text="Issues Detected:" VerticalAlignment="Top"/>
            <ListBox Height="225" Margin="30,209,30,0" VerticalAlignment="Top" ItemsSource="{Binding Errors}" >
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="100"/>
                                            <ColumnDefinition Width="*"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Grid.Column="0" Text="{Binding Title}"/>
                                        <TextBlock Grid.Column="1" Text="{Binding Message}"/>
                                    </Grid>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>

                    </Style>
                </ListBox.ItemContainerStyle>
            </ListBox>
            <Button Content="Continue" Margin="0,0,10,10" HorizontalAlignment="Right" Width="100" Height="32" VerticalAlignment="Bottom"
                Command="{Binding StartRepairCommand}"/>
        </Grid>


        <Grid Visibility="{Binding RepairComplete, Converter={StaticResource BooleanToVisibilityConverter}}">
            <Button Content="Finish" Width="120" HorizontalAlignment="Right" Margin="0,0,10,10" VerticalAlignment="Bottom"
                Command="{Binding CloseCommand}"/>
        </Grid>
    </Grid>
</Controls:CustomWindow>
